<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/5/27
 * Time: 16:40
 */
namespace Home\Controller;
use Think\Controller;

class CommonController extends Controller
{
    function __construct()
    {

        parent::__construct();
        session("userID","17");
        $userID=session("userID");
        D('Cart')->startTrans();

        if(empty($userID))
        {
            $this->redirect("Token/getCode");
        }else{
            //购物车中的商品 和 goods表 进行匹对; 之后 在购物车中删除掉  goods表中 没有的商品
            $arr=D('Cart')->field("goods_id")->where("user_id=".$userID)->select();
            if($arr!="")
            {
                foreach($arr as $ro)
                {
                    $yanG1=D("Goods")->where("id=".$ro['goods_id'])->find();
                    if($yanG1=="")
                    {
                        $res=D('Cart')->where("goods_id=".$ro['goods_id'])->delete();
                        if($res)
                        {
                            D('Cart')->commit();
                        }else{
                            D('Cart')->rollback();
                        }
                    }
                }
            }
            //  操作结束  END
        }
    }
}